package com.doucat.doucatmath.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.doucat.doucatmath.R;
import com.doucat.doucatmath.view.Fx;
import com.doucat.doucatmath.view.FxImageView;
import com.doucat.support.component.fragment.base.BaseFragment;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2021-2031, by tonly, All rights reserved.
 * -----------------------------------------------------------------
 * File: LinearFragment.java
 * Author: wangfy
 * Create: 2021/7/28 15:07
 */
public class TriangleFragment extends BaseFragment {
    private FxImageView imvFx;
    @Override
    public void onRootViewCreate(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setBaseFragmentContentView(R.layout.fragment_triangle);
        imvFx=findViewById(R.id.imvFx);
        imvFx.setD(new double[]{-5,5});
        imvFx.setFx(new Fx() {
            @Override
            public double fx(double x) {
                return 2*Math.sin(2* degToRad(x*60)+Math.PI/2)+1;
            }
        });
    }

    /**
     * 一周的弧度数为2πr/r=2π，360°=2π弧度
     *
     * 1°=π/180*1 rad
     * 2°=π/180*2 rad
     * 3°=π/180*3 rad
     * 4°=π/180*4 rad
     * @param deg
     * @return
     */
    private double degToRad(double deg) {
        return deg * Math.PI / 180;
    }
}